﻿using Clip.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.DataVisualization.Charting;

namespace HangzhouChipProject
{
    class chartUpdata
    {
        public static int chartupdata(Chart c)
        {
            int Sum=new int();
            using (ProductRedcordDBcontext pd = new ProductRedcordDBcontext())
            {
                DateTime nowDate = DateTime.Now.Date;  //获取当前时间
                var dayOfWeek = (int)nowDate.DayOfWeek; //获取当前时间在一周当中的第几天
                if (dayOfWeek == 0)
                    dayOfWeek = 7;
                DateTime dbuffer;  //用于缓存，存储时间队列
                DateTime doffset;    //时间偏移，用于获取当天的产量
                dayOfWeek--;
                //绑定Chart控件显示
                string[] Weeks = new string[] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六","星期日" };
                //存放当天的产量
                int[] CruDayall = new int[7];           
                for (var i = -dayOfWeek; i < 7 - dayOfWeek; i++)
                {
                    dbuffer = nowDate.AddDays(i);
                    doffset = nowDate.AddDays(i+1);
                    CruDayall [i+ dayOfWeek] =   pd.productRecords.Where(a => a.Creatatime > dbuffer && a.Creatatime < doffset).Count();
                  
                }
                c.Series[0].Points.DataBindXY(Weeks, CruDayall);
                for (int i = 0; i < CruDayall.Length; i++)
                {
                    Sum += CruDayall[i];
                }
                return Sum;
            };
           

        }
    }
}
